var upload = function(){


var permissionAdd = new Ext.form.CheckboxGroup({
            xtype: 'checkboxgroup',
            itemCls : 'x-check-group-alt',
            fieldLabel: '权限',
      		columns: 2,
            vertical: true,
            items: [
                {boxLabel: '个人工作台', name: '1', inputValue: 1},
                {boxLabel: '经理工作台', name: '2', inputValue: 2},
                {boxLabel: '合同管理', name: '3', inputValue: 3},
                {boxLabel: '日报', name: '4', inputValue: 4},
                {boxLabel: '消息寻呼', name: '5', inputValue: 5},
                {boxLabel: '资料下载', name: '6', inputValue: 6},
                {boxLabel: '用户设置', name: '7', inputValue: 7},
                {boxLabel: '部门设置', name: '8', inputValue: 8},
                {boxLabel: '角色设置', name: '9', inputValue: 9}
            ]
});
    
var permissionEdit = new Ext.form.CheckboxGroup({
            xtype: 'checkboxgroup',
            itemCls : 'x-check-group-alt',
            fieldLabel: '权限',
      		columns: 2,
            vertical: true,
            items: [
                {boxLabel: '个人工作台', name: '1', inputValue: 1},
                {boxLabel: '经理工作台', name: '2', inputValue: 2},
                {boxLabel: '合同管理', name: '3', inputValue: 3},
                {boxLabel: '日报', name: '4', inputValue: 4},
                {boxLabel: '消息寻呼', name: '5', inputValue: 5},
                {boxLabel: '资料下载', name: '6', inputValue: 6},
                {boxLabel: '用户设置', name: '7', inputValue: 7},
                {boxLabel: '部门设置', name: '8', inputValue: 8},
                {boxLabel: '角色设置', name: '9', inputValue: 9}
            ]
});
 				


var tempvar = new Ext.form.TextField({
		fieldLabel: 'Temp',
		width : 200,
		name:'temp',
		allowBlank: false
	});


	var addRoleName = new Ext.form.TextField({
		fieldLabel: '角色户名称',
		width : 200,
		name:'addRoleName',
		allowBlank: false
	});
	
	
	var departStore = new Ext.data.JsonStore({
			url : '../UserManagement/QueryDepart.form?timesnap=' + new Date().getTime(),
			root : 'result',
				fields : ['DEPARTMENT_ID', 'DEPARTMENT_NAME','ID'],
				listeners : {
					scope : this,
					beforeload : function(thiz) {
						//permissionAdd.items.itemAt(0).setValue(true);
						thiz.baseParams = {
						start : 0,
						limit : 9999
						
						};
					}
					
				}
			});
	
	var departStore2 = new Ext.data.JsonStore({
			url : '../UserManagement/QueryDepart2.form?timesnap=' + new Date().getTime(),
			root : 'result',
				
				fields : ['DEPARTMENT_ID', 'DEPARTMENT_NAME','DOWNDEPART_NAME',
				  'DOWNDEPART_ID','parent_id'],
				listeners : {
					scope : this,
					beforeload : function(thiz) {
						//permissionAdd.items.itemAt(0).setValue(true);
						thiz.baseParams = {
						start : 0,
						limit : 9999
						};
					}
				}
			});
	
	
	
	
	var addDepartName = new Ext.form.ComboBox( {
		fieldLabel : '所属部门',
		//hiddenName : 'type',
		store: departStore2,
		mode : 'local',
		displayField : 'DEPARTMENT_NAME',
		triggerAction : 'all',
		editable : false,
		valueField : 'DEPARTMENT_ID',
		typeAhead : true,
		width : 200,
		selectOnFocus : true,
		selectOnChange : true
		
	});
	
	addDepartName.on('select', function(addDepartName, record, index){
		     
  		//permissionAdd.items.itemAt(0).setValue(true);
	});
	
	var editDepartName = new Ext.form.ComboBox( {
		fieldLabel : '所属部门',
		//hiddenName : 'type',
		store: departStore2,
		mode : 'local',
		displayField : 'DEPARTMENT_NAME',
		triggerAction : 'all',
		editable : false,
		valueField : 'DEPARTMENT_ID',
		typeAhead : true,
		width : 200,
		selectOnFocus : true
	});
		
	var pass="";
	
	
	
	
	var Email = new Ext.form.TextField({
		fieldLabel: 'E-mail',
		width : 200,
		name:'email',
		allowBlank: true
	});
	
	//查找
	var SearchRoleName = new Ext.form.TextField({
	
		fieldLabel: '角色名称',
		width : 200,
		name:'DepartSearchName',
		allowBlank: true
	});
	
	var SearchRoleNum = new Ext.form.TextField({
		fieldLabel: '角色编号',
		width : 200,
		name:'Departnum',
		allowBlank: true
	});
	
	
	
	//修改
	var EditRoleName = new Ext.form.TextField({
		fieldLabel: '角色名称',
		width : 200,
		name:'username',
		allowBlank: false
	});
	var EditRoleNum = new Ext.form.TextField({
		fieldLabel: '角色编号',
		width : 200,
		name:'usernum',
		allowBlank: false,
		disabled:true
	});
	var EditId = new Ext.form.TextField({
		fieldLabel: 'Id',
		width : 200,
		name:'userid',
		allowBlank: false,
		disabled:true
	});
	
	
	//删除
	
	
	
	var addRoleDetail = new Ext.form.FormPanel({
		el:'form',
		labelAlign:'left',
		labwidth:50,
		frame:true,
		
		items : [{layout:'column',defaults:{layout:'form'},
			      items:[{columnWidth:3,items:[addDepartName]},
			      		 {columnWidth:3,items:[addRoleName]},
			      		 {columnWidth:1,items:[permissionAdd]}
			      		 ]
			      }]
	});
	
	createRoleStore= new Ext.data.JsonStore({
		url : '../UserManagement/addRole.form?timesnap=' + new Date().getTime(),
		
				listeners : {
					scope : this,
					beforeload : function(thiz) {
						if( permissionAdd.items.itemAt(0).checked){
							var grgzt = permissionAdd.items.itemAt(0).name;
						}
						if( permissionAdd.items.itemAt(1).checked){
							var glgzt = permissionAdd.items.itemAt(1).name;
						}
						if( permissionAdd.items.itemAt(2).checked){
							var htgl = permissionAdd.items.itemAt(2).name;
						}
						if( permissionAdd.items.itemAt(3).checked){
							var rb = permissionAdd.items.itemAt(3).name;
						}
						if( permissionAdd.items.itemAt(4).checked){
							var xxyh = permissionAdd.items.itemAt(4).name;
						}
						if( permissionAdd.items.itemAt(5).checked){
							var zlxz = permissionAdd.items.itemAt(5).name;
						}
						if( permissionAdd.items.itemAt(6).checked){
							var yhsz = permissionAdd.items.itemAt(6).name;
						}
						if( permissionAdd.items.itemAt(7).checked){
							var bmsz = permissionAdd.items.itemAt(7).name;
						}
						if( permissionAdd.items.itemAt(8).checked){
							var jssz = permissionAdd.items.itemAt(8).name;
						}
							thiz.baseParams = {
								RoleName : addRoleName.getValue(),
								DepartId : addDepartName.getValue(),
								grgzt : grgzt,
								glgzt : glgzt,
								htgl : htgl,
								rb : rb,
								xxyh : xxyh,
								zlxz : zlxz,
								yhsz : yhsz,
								bmsz : bmsz,
								jssz : jssz
						};
					}
				}
			});
	
	
	
	
	var addRole = new Ext.Window({
		el:'addRole',
		layout:'fit',
		title: '添加部门',
        width: 400,
        height:300,
         closeAction: 'hide',
        items:[addRoleDetail],
         buttons:[{text:'确认',icon: '../resources/icons/accept.png',scope:this,handler:function(){
         	var rolename=addRoleName.getValue();
         	var departname=addDepartName.getValue();
         	if ( departname=='' || rolename==''){
         		Utils.warn2('角色名与部门编号不能为空！',180);
         	}else{
         		 createRoleStore.load();
         		 createInfoStore.load();
         		 Utils.info("保存成功","系统提示");
         		 
         		}
         	}},
         	{text:'清空',icon: '../resources/icons/arrow_undo.png',scope:this,handler:function(){
         		permissionAdd.items.itemAt(0).setValue(true);
         		
         	}}
         ],listeners : {
         			"show":function(){
         				for (var i = 0; i <= 8; i++) { 
         					permissionAdd.items.itemAt(i).setValue(false);
         					}
					},
					scope : this,
					beforeload : function(thiz) {
						departStore.load();
						departStore2.load();
					}
					
			}
});


	var search = new Ext.form.FormPanel({
		el:'search',
		labelAlign:'left',
		labwidth:50,
		frame:true,
		items : [{layout:'column',defaults:{layout:'form'},
			      items:[
			      		 {columnWidth:3,items:[SearchRoleName]},
			      		  {columnWidth:3,items:[SearchRoleNum]}
			      		 ]
			      		 }]
			      		 
	});
	

	function Search(){

	}
	
	var delInfoStore = new Ext.data.JsonStore(
			{url : '../UserManagement/DelUser.form?timesnap=' + new Date().getTime(),
				root : 'userInfo',
				fields : ['userId', 'id', 'userName',
						'userDesc', 'userAdmin', 'roleId',
						'branchId', 'createUser', 'createDate', 
						'isActive','beginFlag', 'endFlag', 'departmentId', 'email',
						'phone', 'gender', 'age'],			
						
						
						
				listeners : {
					scope : this,
					beforeload : function(thiz) {
						thiz.baseParams = {
						userName:tempvar.getValue()
						};
					}
				}
			});
	
	
	var saveTract = function(bs){

	}
	
	var createInfoStore = new Ext.data.JsonStore(
			{url : '../UserManagement/QueryRole.form?timesnap=' + new Date().getTime(),
				root : 'result',
				fields : ['DEPARTMENT_ID', 'ROLE_NAME','ID'],
	
				listeners : {
					scope : this,
					beforeload : function(thiz) {
						thiz.baseParams = {
							RoleName : SearchRoleName.getValue(),
							RoleNum : SearchRoleNum.getValue()
						};
					}
				}
	});
	
	var searchRole = new Ext.Window({
		el:'searchRole',
		layout:'fit',
		title: '查询部门',
        width: 400,
        height:300,
         closeAction: 'hide',
        items:[search],
         buttons:[{text:'确认',icon: '../resources/icons/accept.png',scope:this,
         		   handler:function(){
         		   createInfoStore.load();
         	}
         	
         	},
         
         {text:'清空',icon: '../resources/icons/arrow_undo.png',scope:this,handler:function(){
         	}}
         ]
	});

	var edit = new Ext.form.FormPanel({
		el:'edit',
		labelAlign:'left',
		labwidth:50,
		frame:true,
		items : [{layout:'column',defaults:{layout:'form'},
			      items:[{columnWidth:3,items:[EditRoleName]},
			      		 {columnWidth:3,items:[editDepartName]},
			      		 {columnWidth:3,items:[EditId]},
			      		 {columnWidth:1,items:[permissionEdit]}
			      		 ]
			      		 }]
	});
	var xg = Ext.grid;
	var sm = new Ext.grid.CheckboxSelectionModel();
	var createGrid = new Ext.grid.GridPanel({
	sm: sm,
		width : 930,
		height : 300,
		store : createInfoStore,
		scope : this,
		listeners : {
			scope : this,
			rowmousedown : function(grid,index,e){
				var data = grid.store.getAt(index).data;
			}
		},
		columns : [
		sm,{header:'角色编号',sortable: true,width: 150,dataIndex:'ID'},
			{header:'部门编号',sortable: true,width: 150,dataIndex:'DEPARTMENT_ID'},
		    {header:'角色名',sortable: true,width: 100, dataIndex:'ROLE_NAME'}],
		           
       bbar:new Ext.PagingToolbar({
		 pageSize: 10,
         store: createInfoStore,
         displayInfo: true,
         displayMsg: '显示第 {0} 条到 {1} 条记录，一共 {2} 条',
         emptyMsg: "没有记录..."
       })
	});
	
	var agree = new Ext.form.Radio( {
		boxLabel : '是',
		name : 'status',
		checked:true,
		inputValue : 11
	});

	var unAgree = new Ext.form.Radio( {
		boxLabel : '否',
		name : 'status',
		inputValue : 12
	});
	
	var isAgree = new Ext.form.RadioGroup({
		fieldLabel : '是否签约',
		columns : 2,
		items : [agree,unAgree]
	});
	
	var remark = new Ext.form.TextArea({
		fieldLabel : '合同细节',
		width : 840,
		height:200
	});

	var updateRole = new Ext.data.Connection({
		waitTitle : '系统提示',
		waitMsg : '数据提交中，请稍候...',
		url:'../UserManagement/updateRole.form?timesnap=' + new Date().getTime(),
		method:'post'
	});

	var editRole = new Ext.Window({
		el:'editRole',
		layout:'fit',
		title: '修改用户',
        width: 400,
        height:300,
         closeAction: 'hide',
        items:[edit],
         buttons:[{text:'确认',icon: '../resources/icons/accept.png',scope:this,
         		handler:function(){ 
         			Utils.confirm2({
					msg:"是否更改数据信息？",
					width:220,
						fn:function(){
							if( permissionEdit.items.itemAt(0).checked){
								var grgzt = permissionEdit.items.itemAt(0).name;
							}
							if( permissionEdit.items.itemAt(1).checked){
								var glgzt = permissionEdit.items.itemAt(1).name;
							}
							if( permissionEdit.items.itemAt(2).checked){
								var htgl = permissionEdit.items.itemAt(2).name;
							}
							if( permissionEdit.items.itemAt(3).checked){
								var rb = permissionEdit.items.itemAt(3).name;
							}
							if( permissionEdit.items.itemAt(4).checked){
								var xxyh = permissionEdit.items.itemAt(4).name;
							}
							if( permissionEdit.items.itemAt(5).checked){
								var zlxz = permissionEdit.items.itemAt(5).name;
							}
							if( permissionEdit.items.itemAt(6).checked){
								var yhsz = permissionEdit.items.itemAt(6).name;
							}
							if( permissionEdit.items.itemAt(7).checked){
								var bmsz = permissionEdit.items.itemAt(7).name;
							}
							if( permissionEdit.items.itemAt(8).checked){
								var jssz = permissionEdit.items.itemAt(8).name;
							}
							Utils.request(updateRole,{
							params:{
								EditRoleName: EditRoleName.getValue(),
								editDepartName: editDepartName.getValue(),//角色部门
								id: EditId.getValue(),
								grgzt : grgzt,
								glgzt : glgzt,
								htgl : htgl,
								rb : rb,
								xxyh : xxyh,
								zlxz : zlxz,
								yhsz : yhsz,
								bmsz : bmsz,
								jssz : jssz
							},
							success:function(data){
								Utils.info("保存成功","系统提示");	
								createInfoStore.load();
							}
						  })			
						}
					})
         		}
         	},
         {text:'清空',icon: '../resources/icons/arrow_undo.png',scope:this,handler:function(){
         	}}
         ],listeners : {
         			"show":function(){
         				for (var i = 0; i <= 8; i++) { 
         				permissionEdit.items.itemAt(i).setValue(false);
						}
					}
					
			}
	});
	

this.uploadPanel = new Ext.form.FormPanel({

	frame : true,
		width : 800,
		fileUpload: true, 
		labelWidth : 85,
		buttons : [
		           {text:'新增',icon: '../resources/icons/add.png',scope:this,handler:function()
		           		{addRole.show();	}
		           	},
		           {text:'查询',icon: '../resources/icons/find.png',scope:this,handler:function()
		           		{searchRole.show();	}
		           	},
		           	{text:'修改',icon: '../resources/icons/application_edit.png',scope:this,
		           		handler:function(){
		           			var count=createGrid.getSelectionModel().getSelections();
		           			if(count.length==0){
		           				Utils.warn2('请选择一条记录！',180);
								return ;
		           			}else if(count.length>1){
								Utils.warn2('只能选择一条记录！',180);
								return;}
								var ROLE_NAME=count[0].data.ROLE_NAME;
								var DEPARTMENT_ID=count[0].data.DEPARTMENT_ID;
								var ROLE_ID=count[0].data.ID;
								EditRoleName.setValue(ROLE_NAME);
								editDepartName.setValue(DEPARTMENT_ID);
								EditId.setValue(ROLE_ID)
								editRole.show();
								Ext.Ajax.request({ 	
									url : '../UserManagement/QueryRoleAndPermiss.form?timesnap' + new Date().getTime()+'&RoleId='+ROLE_ID,
									
									success : function(response, options) {
										var resultArr = Ext.util.JSON.encode(Ext.util.JSON.decode(response.responseText).result);//.root;
										var count=Ext.util.JSON.decode(response.responseText).result.length;
											for (var i = 0; i < count; i++) { 
												var id=(Ext.util.JSON.decode(response.responseText).result[i].PERMISS_ID)-1;
												permissionEdit.items.itemAt(id).setValue(true); 
											}
											//return dataStr;
										}
								})
								
								
					
						}		           		
		           	}
		           ],
		items : [{layout:'column',defaults:{layout:'form'},
			      items:[]
				},createGrid],
	   listeners: {
	    	render: {fn:function(){ 
				createInfoStore.load();
				departStore.load();
				departStore2.load();
			}}
		}
	});
	//确立查询人员
		var  conn = new Ext.data.Connection({
        method: 'POST',
        url: '../UserManagement/QueryUser.form?timesnap=' + Date.parse(new Date())
    });
	
	
	
	
	
	
	
	//确定立项信息路径
	var addCon = new Ext.data.Connection({
		url:'../project/doCreateProject.form?timesnap=' + new Date().getTime(),
		method:'post'
	});
	
	
	
	var doCreate = function(dp){
			if(projectId!=''){
		    var r = isAgree.getValue();  
		    var value = r.inputValue;  
			Utils.request(addCon,{
				params:{
					project_id:projectId,
					project_status:value,
					remark:remark.getValue()
				},
				success:function(data){
					if(data.result=='true'){
						Utils.info("操作成功","系统提示");	
						createInfoStore.reload();
						dp.getForm().reset();
					}else{
						Utils.info("操作失败","系统提示");	
					}
				}
			});
		}else{
			Utils.info("请选择确定要立项的项目","系统提示");	
		}
	};

};